
************************************
***Project and author information***
************************************

* Project: Mapping digital campaign strategies: How political candidates use social media to communicate constituency connection and policy stance
* Script: GE2020_analysis_final.do
* Date: 13 July 2022
* Authors: James P Cross; Derek Greene; Stefan Müller; Martijn Schoonvelde
* Contact: james.cross@ucd.ie

************************
***Script description***
************************

* This script sorts runs the analysis described in the pre-registration plan found here:
* https://osf.io/78xcq/

***Set seed
set seed 169290015

***Set colour scheme
set scheme plotplainblind, perm

***Set working directory
cd "/Users/jamescross/Dropbox/GE2020/Images/Data/Data_Analysis"

***Load data
clear
use "./data_analysis.dta"

*Encode variables
rename dv_categories dv_categories_temp
encode dv_categories_temp, gen(dv_categories)
drop dv_categories_temp

rename campaign campaign_temp
encode campaign_temp, gen(campaign)
drop campaign_temp

rename gender gender_temp
encode gender_temp, gen(gender)
drop gender_temp

rename party party_temp
encode party_temp, gen(party)
drop party_temp

rename urban_rural urban_rural_temp
encode urban_rural_temp, gen(urban_rural)
drop urban_rural_temp

*Destring birth seniority year_clean election_year
destring birth seniority year_clean election_year, replace

*Create age variable
gen age = 2020 - birth

*Label variables
label variable competitiveness "Competitiveness"
label variable sum_running "Previous campaign experience"
label variable gender "Gender"
label variable campaign "Campaign"
label variable time_until_election "Time until election"
label variable party "Party"
label variable urban_rural "Urban/Rural"
label variable twitter_length "Twitter length"
label variable followers_count "Followers count"
label variable rolavg_ntweets_7 "Rolling average of no. of tweets (7 days)"
label variable rolavg_retweets_7 "Rolling average of retweets (7 days)"
label variable rolavg_likes_7 "Rolling average of likes (7 days)"
label variable sum_likes_10_tweet "Sum of likes on previous 10 tweets"
label variable sum_retweets_10_tweet "Sum of retweets on previous 10 tweets"
label variable sum_electioneering_10_tweet "Sum of electioneering in previous 10 tweets"
label variable mean_retweets_electioneering_10 "Mean retweets on electioneering (10 tweets)"
label variable sum_policy_10_tweet "Sum of policy in previous 10 tweets"
label variable mean_retweets_policy_10 "Mean retweets on policy (10 tweets)"
label variable age "Age"
label variable first_pref_share "First preference share"
label variable district_magnitude_man "District magnitude"
label variable candidates_running_const "Candidates running"
label variable dv_categories "Campaign strategy choice"

*Clear saved models and figures
graph drop _all
est drop _all

******************
***PAPER MODELS***
******************

***Model 1 - Basic with interaction terms
mlogit dv_categories c.competitiveness##ib2.campaign c.sum_running##ib2.campaign i.gender##ib2.campaign ///
	c.time_until_election i.party c.district_magnitude_man c.candidates_running_const i.urban_rural c.twitter_length c.followers_count, ///
	vce(cluster screen_name) rrr

*Table 2
esttab using "../../Output/Tables/tab_02.tex", ///
	order(competitiveness sum_running gender campaign) ///
	label mlabels(none) collabels(none) wide nobaselevels unstack eform noomitted fragment replace
	
*Figure 8 for Model 1 with campaign period
coefplot (., keep(Electioneering:)) (., keep(Policy:)) (., keep(Both:)), bylabel(Both) ///
        ||, drop(_cons *.party followers_count twitter_length rolavg_ntweets_7 followers_count ///
		time_until_election party district_magnitude_man candidates_running_const urban_rural) ///
		xline(1) eform  xtitle(Relative risk ratios) name(c1, replace)
graph export  ../../Output/Figures/fig_08.pdf, name(c1) replace

***Model 2 - campaign dynamics
mlogit dv_categories c.competitiveness c.sum_running i.gender ib2.campaign ///
	c.time_until_election i.party c.district_magnitude_man c.candidates_running_const i.urban_rural c.twitter_length c.followers_count ///
	c.rolavg_ntweets_7 c.rolavg_retweets_7 c.sum_likes_10_tweet c.sum_retweets_10_tweet ///
	c.sum_electioneering_10_tweet c.mean_retweets_electioneering_10 c.sum_policy_10_tweet c.mean_retweets_policy_10, ///
	vce(cluster screen_name) rrr

*Table 3
esttab using "../../Output/Tables/tab_03.tex", ///
	order(competitiveness sum_running gender campaign) ///
	label mlabels(none) collabels(none) wide nobaselevels unstack eform noomitted fragment replace
	
*Figure 9 for model 2
coefplot (., keep(Electioneering:)) (., keep(Policy:)) (., keep(Both:)), bylabel(Both) ///
        ||, drop(_cons *.campaign *.party followers_count twitter_length rolavg_ntweets_7 followers_count ///
		sum_likes_10_tweet sum_retweets_10_tweet rolavg_retweets_7 rolavg_likes_7 ) ///
		xline(1) eform  xtitle(Relative risk ratios) name(c2, replace)
graph export  ../../Output/Figures/fig_09.pdf, name(c2) replace

*********************************************
***Appendix 4 - Alternative specifications***
*********************************************

***Model A1 - Pre-registered regression
mlogit dv_categories c.competitiveness i.campaign c.sum_running i.gender c.time_until_election i.party ///
	c.district_magnitude_man c.candidates_running_const i.urban_rural c.twitter_length c.followers_count ///
	c.rolavg_ntweets_7 c.sum_likes_10_tweet c.sum_retweets_10_tweet c.rolavg_retweets_7, ///
	vce(cluster screen_name) rrr
*estimates store m1_CSE_appendix

*Table A6 for Model A1
esttab using "../../Output/Tables/tab_a06.tex", ///
	order(competitiveness sum_running gender campaign) ///
	label mlabels(none) collabels(none) wide nobaselevels unstack eform noomitted fragment replace


*Model A2 - without clustered SEs
mlogit dv_categories c.competitiveness##ib2.campaign c.sum_running##ib2.campaign i.gender##ib2.campaign ///
	c.time_until_election i.party c.district_magnitude_man c.candidates_running_const i.urban_rural ///
	c.twitter_length c.followers_count c.rolavg_ntweets_7 c.rolavg_retweets_7 c.sum_likes_10_tweet ///
	c.sum_retweets_10_tweet, rrr

*Table A7 for Model A2
esttab using "../../Output/Tables/tab_a07.tex", ///
	order(competitiveness sum_running gender campaign) ///
	label mlabels(none) collabels(none) wide nobaselevels unstack eform noomitted fragment replace
	

*Model A3 - First preference vote in previous election as competitiveness alternative
mlogit dv_categories c.first_pref_share##ib2.campaign c.sum_running##ib2.campaign i.gender##ib2.campaign ///
	c.time_until_election i.party c.district_magnitude_man c.candidates_running_const i.urban_rural ///
	c.twitter_length c.followers_count c.rolavg_ntweets_7 c.rolavg_retweets_7 c.sum_likes_10_tweet ///
	c.sum_retweets_10_tweet, vce(cluster screen_name) rrr

*Table A8 for Model A3
esttab using "../../Output/Tables/tab_a08.tex", ///
	order(competitiveness sum_running gender campaign) ///
	label mlabels(none) collabels(none) wide nobaselevels unstack eform noomitted fragment replace
	

*Model A4 - Age as experience control
mlogit dv_categories c.competitiveness##ib2.campaign c.sum_running##ib2.campaign i.gender##ib2.campaign c.age ///
	c.time_until_election i.party c.district_magnitude_man c.candidates_running_const i.urban_rural ///
	c.twitter_length c.followers_count c.rolavg_ntweets_7 c.rolavg_retweets_7 c.sum_likes_10_tweet ///
	c.sum_retweets_10_tweet, vce(cluster screen_name) rrr

*Table A9 for Model A4
esttab using "../../Output/Tables/tab_a09.tex", ///
	order(competitiveness sum_running gender campaign) ///
	label mlabels(none) collabels(none) wide nobaselevels unstack eform noomitted fragment replace
	
